package com.daxt.common.config;

import java.io.File;
import java.sql.Connection;

import javax.sql.DataSource;

import com.daxt.base.common.util.RedisUtil;
import com.daxt.model.dic.SystemConfigType;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

@Component
public class ValidateDataSource implements ApplicationContextAware {

	private static ApplicationContext context;

	@Value("spring.datasource.username")
	private static String bbb;

	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		String tempPath = RedisUtil.getSysConfig(SystemConfigType.TEMP_PATH);
		File file=new File(tempPath);
		file.mkdirs();
		try {
		context = applicationContext;
		System.out.println("数据库连接" + "----------------------------");
		DataSource dataSource = (DataSource) context.getBean("dataSource");
		Connection connection = dataSource.getConnection();
		System.out.println(connection.toString());
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(-1);
		}
	}

	public ApplicationContext getApplicationContext() {
		return context;
	}

}
